package com.citrix.gs.util.beacon.job;

import java.text.MessageFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.citrix.gs.util.RepositoryDeployer;
import com.citrix.gs.util.beacon.BeaconJobType;
import com.citrix.gs.util.beacon.ToolType;

public class BeaconToolJob extends BeaconJob implements Deployable {
    
    @SuppressWarnings("unused")
    private static Logger logger = LoggerFactory.getLogger(BeaconToolJob.class);
	
	private ToolType toolType;
	
	public BeaconToolJob(RepositoryDeployer deployer, ToolType toolType) {
		super(deployer);
		this.jobType = BeaconJobType.Tool;
		this.toolType = toolType;
		this.jobName = this.toolType.name() +  "-" + repo.getName();
		this.tempFile = jobType.name().toLowerCase() + "_template.xml";
	}

	@Override
	public void add() {
		
		if(beforeAdd() && editAssignedNode() && editAuthToken() 
				&& editUpstreamJob(BeaconJobType.Toolset.name())// watch upstream job
				&& editToolCommand()
				&& editToolResultArchive()
				&& editNextJob(BeaconJobType.DataImporter.name())
				&& editNodeStalkerBuildWrapper()
				&& createJob()){}
		else {}
	}
	
	private boolean editToolCommand() {
		String command = MessageFormat.format("py tools\\CIScripts\\{0}.py", toolType.name());
		return editBuildCommand(command);
	}
	
	private boolean editToolResultArchive(){
		
		String artifacts = MessageFormat.format("{0}*.csv", toolType.name());
		return editArtifactArchiver(artifacts);
	}

    @Override
    public void move() {
        if(beforeMove() && moveJob()) {
            
        } else {
            
        }
    }
}
